package Presentation;

import BusinessLogic.AutoSmiles;
import BusinessLogic.Command;
import BusinessLogic.Connection;
import BusinessLogic.Sound;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.*;


public final class frmChat extends javax.swing.JFrame {
    private String username;
    private String state;
    private int count;
    private int watch;
    
    public frmChat() {
        initComponents();
        this.setLocation(350, 100);
        setIcon();
        pn_smiley.setVisible(false);
        btn_Send.setEnabled(false);
        tf_message.requestFocusInWindow();
        messageListen();
        AutoSmiles.initListener(tp_log);
    }
     public frmChat(String username) {
        initComponents();
        this.setLocation(350, 100);
        setIcon();
        pn_smiley.setVisible(false);
        btn_Send.setEnabled(false);
        tf_message.requestFocusInWindow();
        setUsername(username);
        messageListen();
        AutoSmiles.initListener(tp_log);
    }
    
    private void setIcon() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Images/icon.png")));
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pn_smiley = new javax.swing.JPanel();
        smile1 = new javax.swing.JLabel();
        smile2 = new javax.swing.JLabel();
        smile3 = new javax.swing.JLabel();
        smile4 = new javax.swing.JLabel();
        smile5 = new javax.swing.JLabel();
        smile6 = new javax.swing.JLabel();
        smile7 = new javax.swing.JLabel();
        smile8 = new javax.swing.JLabel();
        smile9 = new javax.swing.JLabel();
        smile10 = new javax.swing.JLabel();
        smile11 = new javax.swing.JLabel();
        smile12 = new javax.swing.JLabel();
        smile13 = new javax.swing.JLabel();
        smile14 = new javax.swing.JLabel();
        smile15 = new javax.swing.JLabel();
        smile16 = new javax.swing.JLabel();
        smile17 = new javax.swing.JLabel();
        smile18 = new javax.swing.JLabel();
        smile19 = new javax.swing.JLabel();
        smile20 = new javax.swing.JLabel();
        smile21 = new javax.swing.JLabel();
        smile22 = new javax.swing.JLabel();
        smile23 = new javax.swing.JLabel();
        smile24 = new javax.swing.JLabel();
        lb_smile = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lbl_chatfriend = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lbl_lock = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tp_log = new javax.swing.JTextPane();
        jPanel3 = new javax.swing.JPanel();
        btn_Send = new javax.swing.JButton();
        tf_message = new javax.swing.JTextField();
        cbo_font = new javax.swing.JComboBox();
        cbo_size = new javax.swing.JComboBox();
        btn_B = new javax.swing.JToggleButton();
        btn_I = new javax.swing.JToggleButton();
        btn_U = new javax.swing.JToggleButton();
        buzz = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        mn_hoithoai = new javax.swing.JMenu();
        mni_New = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mni_Close = new javax.swing.JMenuItem();
        mn_chucnang = new javax.swing.JMenu();
        mnu_Friend = new javax.swing.JMenu();
        mni_Lock = new javax.swing.JMenuItem();
        mni_Unlock = new javax.swing.JMenuItem();
        mni_AddFriend = new javax.swing.JMenuItem();
        mn_Help = new javax.swing.JMenu();
        mni_Info = new javax.swing.JMenuItem();

        setBackground(new java.awt.Color(204, 204, 255));
        setName("frm_khungchat"); // NOI18N
        setResizable(false);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        pn_smiley.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(51, 153, 255)));
        pn_smiley.setDoubleBuffered(false);
        pn_smiley.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        smile1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/1.png")));
        smile1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile1.setOpaque(true);
        smile1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile1.setBackground(new java.awt.Color(51, 204, 255));
                smile1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile1.setToolTipText("vui vẻ");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":)");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile1.setBackground(null);
                smile1.setBorder(null);
            }
        });
        pn_smiley.add(smile1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 30, 20));

        smile2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/2.png")));
        smile2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile2.setOpaque(true);
        smile2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile2.setBackground(new java.awt.Color(51, 204, 255));
                smile2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile2.setToolTipText("nhăn mặt");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":(");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile2.setBackground(null);
                smile2.setBorder(null);
            }
        });
        pn_smiley.add(smile2, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 10, 30, 20));

        smile3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/3.png")));
        smile3.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile3.setOpaque(true);
        smile3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile3.setBackground(new java.awt.Color(51, 204, 255));
                smile3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile3.setToolTipText("nháy mắt");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+";)");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile3.setBackground(null);
                smile3.setBorder(null);
            }
        });
        pn_smiley.add(smile3, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 10, 30, 20));

        smile4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/4.png")));
        smile4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile4.setOpaque(true);
        smile4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile4.setBackground(new java.awt.Color(51, 204, 255));
                smile4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile4.setToolTipText("cười nhe răng");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":D");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile4.setBackground(null);
                smile4.setBorder(null);
            }
        });
        pn_smiley.add(smile4, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 10, 30, 20));

        smile5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/5.png")));
        smile5.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile5.setOpaque(true);
        smile5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile5.setBackground(new java.awt.Color(51, 204, 255));
                smile5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile5.setToolTipText("đá lông nheo");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+";;)");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile5.setBackground(null);
                smile5.setBorder(null);
            }
        });
        pn_smiley.add(smile5, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 10, 30, 20));

        smile6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/6.png")));
        smile6.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile6.setOpaque(true);
        smile6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile6.setBackground(new java.awt.Color(51, 204, 255));
                smile6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile6.setToolTipText("ôm 1 cái");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+">:D<");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile6.setBackground(null);
                smile6.setBorder(null);
            }
        });
        pn_smiley.add(smile6, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 10, 30, 20));

        smile7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/7.png")));
        smile7.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile7.setOpaque(true);
        smile7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile7.setBackground(new java.awt.Color(51, 204, 255));
                smile7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile7.setToolTipText("bối rối");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":-/");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile7.setBackground(null);
                smile7.setBorder(null);
            }
        });
        pn_smiley.add(smile7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 30, 20));

        smile8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/8.png")));
        smile8.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile8.setOpaque(true);
        smile8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile8.setBackground(new java.awt.Color(51, 204, 255));
                smile8.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile8.setToolTipText("đang yêu");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":x");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile8.setBackground(null);
                smile8.setBorder(null);
            }
        });
        pn_smiley.add(smile8, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 40, 30, 20));

        smile9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/9.png")));
        smile9.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile9.setOpaque(true);
        smile9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile9.setBackground(new java.awt.Color(51, 204, 255));
                smile9.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile9.setToolTipText("thẹn thùng");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":$");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile9.setBackground(null);
                smile9.setBorder(null);
            }
        });
        pn_smiley.add(smile9, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 40, 30, 20));

        smile10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/10.png")));
        smile10.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile10.setOpaque(true);
        smile10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile10.setBackground(new java.awt.Color(51, 204, 255));
                smile10.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile10.setToolTipText("lè lưỡi");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":-P");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile10.setBackground(null);
                smile10.setBorder(null);
            }
        });
        pn_smiley.add(smile10, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 40, 30, 20));

        smile11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/11.png")));
        smile11.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile11.setOpaque(true);
        smile11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile11.setBackground(new java.awt.Color(51, 204, 255));
                smile11.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile11.setToolTipText("hôn");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":-*");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile11.setBackground(null);
                smile11.setBorder(null);
            }
        });
        pn_smiley.add(smile11, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 40, 30, 20));

        smile12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/12.png")));
        smile12.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile12.setOpaque(true);
        smile12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile12.setBackground(new java.awt.Color(51, 204, 255));
                smile12.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile12.setToolTipText("tan nát cõi lòng");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+"=((");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile12.setBackground(null);
                smile12.setBorder(null);
            }
        });
        pn_smiley.add(smile12, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 40, 30, 20));

        smile13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/13.png")));
        smile13.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile13.setOpaque(true);
        smile13.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile13.setBackground(new java.awt.Color(51, 204, 255));
                smile13.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile13.setToolTipText("ngạc nhiên");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":-O");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile13.setBackground(null);
                smile13.setBorder(null);
            }
        });
        pn_smiley.add(smile13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 30, 20));

        smile14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/14.png")));
        smile14.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile14.setOpaque(true);
        smile14.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile14.setBackground(new java.awt.Color(51, 204, 255));
                smile14.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile14.setToolTipText("tức giận");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+"X-(");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile14.setBackground(null);
                smile14.setBorder(null);
            }
        });
        pn_smiley.add(smile14, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 70, 30, 20));

        smile15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/15.png")));
        smile15.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile15.setOpaque(true);
        smile15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile15.setBackground(new java.awt.Color(51, 204, 255));
                smile15.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile15.setToolTipText("vênh mặt");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":->");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile15.setBackground(null);
                smile15.setBorder(null);
            }
        });
        pn_smiley.add(smile15, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 70, 30, 20));

        smile16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/16.png")));
        smile16.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile16.setOpaque(true);
        smile16.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile16.setBackground(new java.awt.Color(51, 204, 255));
                smile16.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile16.setToolTipText("ngầu");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+"B-)");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile16.setBackground(null);
                smile16.setBorder(null);
            }
        });
        pn_smiley.add(smile16, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 70, 30, 20));

        smile17.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/17.png")));
        smile17.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile17.setOpaque(true);
        smile17.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile17.setBackground(new java.awt.Color(51, 204, 255));
                smile17.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile17.setToolTipText("lo lắng");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":-S");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile17.setBackground(null);
                smile17.setBorder(null);
            }
        });
        pn_smiley.add(smile17, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 70, 30, 20));

        smile18.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/18.png")));
        smile18.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile18.setOpaque(true);
        smile18.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile18.setBackground(new java.awt.Color(51, 204, 255));
                smile18.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile18.setToolTipText("phù");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+"#:-S");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile18.setBackground(null);
                smile18.setBorder(null);
            }
        });
        pn_smiley.add(smile18, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 70, 30, 20));

        smile19.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/19.png")));
        smile19.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile19.setOpaque(true);
        smile19.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile19.setBackground(new java.awt.Color(51, 204, 255));
                smile19.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile19.setToolTipText("quỷ sứ");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+">;:");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile19.setBackground(null);
                smile19.setBorder(null);
            }
        });
        pn_smiley.add(smile19, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 100, 30, 20));

        smile20.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/20.png")));
        smile20.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile20.setOpaque(true);
        smile20.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile20.setBackground(new java.awt.Color(51, 204, 255));
                smile20.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile20.setToolTipText("khóc");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":-((");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile20.setBackground(null);
                smile20.setBorder(null);
            }
        });
        pn_smiley.add(smile20, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 100, 30, 20));

        smile21.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile21.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/21.png")));
        smile21.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile21.setOpaque(true);
        smile21.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile21.setBackground(new java.awt.Color(51, 204, 255));
                smile21.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile21.setToolTipText("cười ngoác miệng");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":-))");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile21.setBackground(null);
                smile21.setBorder(null);
            }
        });
        pn_smiley.add(smile21, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 100, 30, 20));

        smile22.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile22.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/22.png")));
        smile22.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile22.setOpaque(true);
        smile22.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile22.setBackground(new java.awt.Color(51, 204, 255));
                smile22.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile22.setToolTipText("chịu");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+":|");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile22.setBackground(null);
                smile22.setBorder(null);
            }
        });
        pn_smiley.add(smile22, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 100, 30, 20));

        smile23.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile23.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/23.png")));
        smile23.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile23.setOpaque(true);
        smile23.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile23.setBackground(new java.awt.Color(51, 204, 255));
                smile23.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile23.setToolTipText("nhíu mày");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+"/:)");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile23.setBackground(null);
                smile23.setBorder(null);
            }
        });
        pn_smiley.add(smile23, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 100, 30, 20));

        smile24.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        smile24.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Smiley/24.png")));
        smile24.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        smile24.setOpaque(true);
        smile24.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                smile24.setBackground(new java.awt.Color(51, 204, 255));
                smile24.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 153, 255)));
                smile24.setToolTipText("cười lăn lộn");
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tf_message.setText(tf_message.getText()+"=))");
                pn_smiley.setVisible(false);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                smile24.setBackground(null);
                smile24.setBorder(null);
            }
        });
        pn_smiley.add(smile24, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 100, 30, 20));

        getContentPane().add(pn_smiley, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 295, 250, 130));

        lb_smile.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/smiley1.png")));
        lb_smile.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lb_smile.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lb_smileMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lb_smileMouseExited(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lb_smileMouseClicked(evt);
            }
        });
        getContentPane().add(lb_smile, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 300, 30, 20));

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setText("G_IT");

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 12)); // NOI18N
        jLabel3.setText("Đang chat với:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel3)
                .addGap(6, 6, 6)
                .addComponent(lbl_chatfriend, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addComponent(lbl_lock, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(lbl_chatfriend, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(lbl_lock, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel1))
        );

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 444, 40));

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        tp_log.setEditable(false);
        tp_log.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        tp_log.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tp_logMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tp_log);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 444, 241));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 50, 444, -1));

        jPanel3.setBackground(new java.awt.Color(204, 204, 255));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btn_Send.setBackground(new java.awt.Color(204, 204, 255));
        btn_Send.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        btn_Send.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Comment.png"))); // NOI18N
        btn_Send.setBorder(null);
        btn_Send.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btn_Send.setName("btn_send"); // NOI18N
        btn_Send.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btn_SendMouseEntered(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btn_SendMouseClicked(evt);
            }
        });
        btn_Send.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_SendActionPerformed(evt);
            }
        });
        jPanel3.add(btn_Send, new org.netbeans.lib.awtextra.AbsoluteConstraints(381, 11, 59, 42));

        tf_message.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        tf_message.setBorder(BorderFactory.createCompoundBorder(
            tf_message.getBorder(), 
            BorderFactory.createEmptyBorder(0, 5, 0, 0)));
    tf_message.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            tf_messageMouseClicked(evt);
        }
    });
    tf_message.addInputMethodListener(new java.awt.event.InputMethodListener() {
        public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            tf_messageInputMethodTextChanged(evt);
        }
        public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
        }
    });
    tf_message.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            tf_messageKeyPressed(evt);
        }
    });
    jPanel3.add(tf_message, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 12, 361, 42));

    getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 340, 444, 70));

    cbo_font.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arial", "Arial Black", "Calibri", "Courier New", "Times New Roman", "Tahoma", "Verdana", "Segoe UI Light" }));
    cbo_font.setName("cb_font"); // NOI18N
    cbo_font.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            cbo_fontMouseEntered(evt);
        }
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            cbo_fontMouseClicked(evt);
        }
    });
    cbo_font.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cbo_fontActionPerformed(evt);
        }
    });
    getContentPane().add(cbo_font, new org.netbeans.lib.awtextra.AbsoluteConstraints(237, 297, 150, -1));

    cbo_size.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "12", "13", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "" }));
    cbo_size.setName("cb_size"); // NOI18N
    cbo_size.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            cbo_sizeMouseEntered(evt);
        }
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            cbo_sizeMouseClicked(evt);
        }
    });
    getContentPane().add(cbo_size, new org.netbeans.lib.awtextra.AbsoluteConstraints(397, 297, -1, -1));

    btn_B.setText("B");
    btn_B.setBorder(null);
    btn_B.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    btn_B.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            btn_BMouseEntered(evt);
        }
    });
    getContentPane().add(btn_B, new org.netbeans.lib.awtextra.AbsoluteConstraints(85, 300, 34, 20));

    btn_I.setText("I");
    btn_I.setBorder(null);
    btn_I.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    btn_I.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            btn_IMouseEntered(evt);
        }
    });
    getContentPane().add(btn_I, new org.netbeans.lib.awtextra.AbsoluteConstraints(125, 300, 38, 20));

    btn_U.setText("U");
    btn_U.setBorder(null);
    btn_U.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    btn_U.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            btn_UMouseEntered(evt);
        }
    });
    getContentPane().add(btn_U, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 300, 38, 20));

    buzz.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/buzz1.png"))); // NOI18N
    buzz.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    buzz.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            buzzMouseClicked(evt);
        }
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            buzzMouseEntered(evt);
        }
        public void mouseExited(java.awt.event.MouseEvent evt) {
            buzzMouseExited(evt);
        }
    });
    getContentPane().add(buzz, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 300, -1, -1));

    jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/style.png"))); // NOI18N
    getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 300, 42, 35));

    jMenuBar1.setForeground(new java.awt.Color(0, 153, 153));
    jMenuBar1.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            jMenuBar1MouseClicked(evt);
        }
    });

    mn_hoithoai.setText("Hội thoại");

    mni_New.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
    mni_New.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/new_message.png"))); // NOI18N
    mni_New.setText("Mới");
    mni_New.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_NewActionPerformed(evt);
        }
    });
    mn_hoithoai.add(mni_New);
    mn_hoithoai.add(jSeparator1);

    mni_Close.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
    mni_Close.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/close_window.png"))); // NOI18N
    mni_Close.setText("Đóng");
    mni_Close.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_CloseActionPerformed(evt);
        }
    });
    mn_hoithoai.add(mni_Close);

    jMenuBar1.add(mn_hoithoai);

    mn_chucnang.setText("Chức năng");

    mnu_Friend.setText("Người dùng");

    mni_Lock.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/lock_go.png"))); // NOI18N
    mni_Lock.setText("Khóa người dùng");
    mni_Lock.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_LockActionPerformed(evt);
        }
    });
    mnu_Friend.add(mni_Lock);

    mni_Unlock.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/lock_open.png"))); // NOI18N
    mni_Unlock.setText("Mở khóa người dùng");
    mni_Unlock.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_UnlockActionPerformed(evt);
        }
    });
    mnu_Friend.add(mni_Unlock);

    mn_chucnang.add(mnu_Friend);

    mni_AddFriend.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
    mni_AddFriend.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/add (2).png"))); // NOI18N
    mni_AddFriend.setText("Thêm bạn");
    mni_AddFriend.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_AddFriendActionPerformed(evt);
        }
    });
    mn_chucnang.add(mni_AddFriend);

    jMenuBar1.add(mn_chucnang);

    mn_Help.setText("Trợ giúp");

    mni_Info.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
    mni_Info.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/house.png"))); // NOI18N
    mni_Info.setText("Thông tin");
    mni_Info.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_InfoActionPerformed(evt);
        }
    });
    mn_Help.add(mni_Info);

    jMenuBar1.add(mn_Help);

    setJMenuBar(jMenuBar1);

    pack();
    }// </editor-fold>//GEN-END:initComponents

    
    private void btn_SendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SendActionPerformed
        if(!tf_message.getText().equals("")){
            String style=getStyle();
            myMessage(tf_message.getText());
            Connection.sendData(Command.MESSAGE_SEND+style+username+(char)(001)+lbl_chatfriend.getText()+(char)(002)+tf_message.getText());
            tf_message.setText("");
            tf_message.requestFocus();
        }
    }//GEN-LAST:event_btn_SendActionPerformed
    private void cbo_fontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbo_fontActionPerformed
        
    }//GEN-LAST:event_cbo_fontActionPerformed
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

    }//GEN-LAST:event_formWindowOpened

    private void mni_AddFriendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_AddFriendActionPerformed
        frmAddFriend kb=new frmAddFriend();
        kb.setVisible(true);
    }//GEN-LAST:event_mni_AddFriendActionPerformed
    private void mni_CloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_CloseActionPerformed
       this.setVisible(false);
    }//GEN-LAST:event_mni_CloseActionPerformed
    private void mni_InfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_InfoActionPerformed
        JOptionPane.showMessageDialog(null, "- Chương trình Chat Application\n-  Version: 1.0\n- Nhóm thực hiện: G_IT\n- Khoa CNTT & TT đại học Cần Thơ 2013");
    }//GEN-LAST:event_mni_InfoActionPerformed

private void tf_messageKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_messageKeyPressed
    if(evt.getKeyCode() == KeyEvent.VK_ENTER){
       btn_SendActionPerformed(null);
    }
}//GEN-LAST:event_tf_messageKeyPressed

private void buzzMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buzzMouseEntered
    buzz.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/buzz2.png")));
    buzz.setToolTipText("BUZZ");
}//GEN-LAST:event_buzzMouseEntered

private void buzzMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buzzMouseExited
    buzz.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/buzz1.png")));
}//GEN-LAST:event_buzzMouseExited

private void buzzMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buzzMouseClicked
    alert();
    Connection.sendData(Command.BUZZ+username+(char)(001)+lbl_chatfriend.getText());
}//GEN-LAST:event_buzzMouseClicked

private void btn_BMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_BMouseEntered
    btn_B.setToolTipText("In đậm");
}//GEN-LAST:event_btn_BMouseEntered

private void btn_IMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_IMouseEntered
    btn_I.setToolTipText("In nghiêng");
}//GEN-LAST:event_btn_IMouseEntered

private void btn_UMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_UMouseEntered
    btn_U.setToolTipText("Gạch chân");
}//GEN-LAST:event_btn_UMouseEntered

private void cbo_fontMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbo_fontMouseEntered
    cbo_font.setToolTipText("Chọn font chữ");
}//GEN-LAST:event_cbo_fontMouseEntered

private void cbo_sizeMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbo_sizeMouseEntered
    cbo_size.setToolTipText("Kích cỡ chữ");
}//GEN-LAST:event_cbo_sizeMouseEntered

private void btn_SendMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_SendMouseEntered
    btn_Send.setToolTipText("Gửi");
}//GEN-LAST:event_btn_SendMouseEntered

    private void tf_messageInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_tf_messageInputMethodTextChanged
        if(tf_message.getText().equals(""))
            btn_Send.setEnabled(false);
        else btn_Send.setEnabled(true);
    }//GEN-LAST:event_tf_messageInputMethodTextChanged

    private void mni_LockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_LockActionPerformed
        Connection.sendData(Command.LOCK_FRIEND_REQUEST+username+((char)001)+lbl_chatfriend.getText());
    }//GEN-LAST:event_mni_LockActionPerformed

    private void mni_UnlockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_UnlockActionPerformed
        Connection.sendData(Command.UNLOCK_FRIEND_REQUEST+username+((char)001)+lbl_chatfriend.getText());
    }//GEN-LAST:event_mni_UnlockActionPerformed

    private void lb_smileMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lb_smileMouseEntered
        lb_smile.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/smiley2.png")));
    }//GEN-LAST:event_lb_smileMouseEntered

    private void lb_smileMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lb_smileMouseClicked
        if(pn_smiley.isVisible()){
            pn_smiley.setVisible(false);
        }
        else{
            pn_smiley.requestFocus();
            pn_smiley.setVisible(true);
        }
    }//GEN-LAST:event_lb_smileMouseClicked

    private void lb_smileMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lb_smileMouseExited
        lb_smile.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/smiley1.png")));
    }//GEN-LAST:event_lb_smileMouseExited

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        pn_smiley.setVisible(false);
    }//GEN-LAST:event_formMouseClicked

    private void tf_messageMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tf_messageMouseClicked
        pn_smiley.setVisible(false);
    }//GEN-LAST:event_tf_messageMouseClicked

    private void tp_logMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tp_logMouseClicked
        pn_smiley.setVisible(false);
    }//GEN-LAST:event_tp_logMouseClicked

    private void jMenuBar1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuBar1MouseClicked
        pn_smiley.setVisible(false);
    }//GEN-LAST:event_jMenuBar1MouseClicked

    private void cbo_fontMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbo_fontMouseClicked
        pn_smiley.setVisible(false);
    }//GEN-LAST:event_cbo_fontMouseClicked

    private void cbo_sizeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbo_sizeMouseClicked
        pn_smiley.setVisible(false);
    }//GEN-LAST:event_cbo_sizeMouseClicked

    private void btn_SendMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_SendMouseClicked
        pn_smiley.setVisible(false);
    }//GEN-LAST:event_btn_SendMouseClicked

    private void mni_NewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_NewActionPerformed
        tp_log.setText("");
    }//GEN-LAST:event_mni_NewActionPerformed
    private void messageListen() {
        tf_message.getDocument().addDocumentListener(new DocumentListener() {

            public void insertUpdate(DocumentEvent e) {
                if(!tf_message.getText().equals(""))
                    btn_Send.setEnabled(true);
                else btn_Send.setEnabled(false);
            }

            public void removeUpdate(DocumentEvent e) {
                if(!tf_message.getText().equals(""))
                    btn_Send.setEnabled(true);
                else btn_Send.setEnabled(false);
            }

            public void changedUpdate(DocumentEvent e) {
                
            }
        });
    }
    
    public void alert(){
        try {
            new Sound().play("buzz");
            final int originalX = this.getLocationOnScreen().x; 
            final int originalY = this.getLocationOnScreen().y; 
            for(int i = 0; i < 5; i++) { 
                Thread.sleep(10); 
                this.setLocation(originalX, originalY + 5); 
                Thread.sleep(10); 
                this.setLocation(originalX, originalY - 5);
                Thread.sleep(10); 
                this.setLocation(originalX + 5, originalY);
                Thread.sleep(10); 
                this.setLocation(originalX, originalY); 
            } 
        } 
        catch (Exception err) {
        }
        StyledDocument d = tp_log.getStyledDocument();
        SimpleAttributeSet b = new SimpleAttributeSet();
        StyleConstants.setForeground(b, Color.RED);
        StyleConstants.setBold(b, true);
        try {
            d.insertString(d.getLength(),"BUZZ!!!\n", b);
            tp_log.select(d.getLength(), d.getLength());
        } catch (BadLocationException ex) {
        }
    }
    
    public void setState(String st){
        state=st;
    }
    
    public void checkLock(boolean a){
        if(a==true){
            lbl_lock.setIcon(new ImageIcon(getClass().getResource("/Images/lock_go.png")));
        }
        else{
            lbl_lock.setIcon(null);
        }
    }
    
    public void setFriend(String friend, int sta){
        switch(sta){
            case(0):
                lbl_chatfriend.setIcon(new ImageIcon(getClass().getResource("/Images/status_offline.png")));
                break;
            case(1):
                lbl_chatfriend.setIcon(new ImageIcon(getClass().getResource("/Images/status_online.png")));
                break;
            case(2):
                lbl_chatfriend.setIcon(new ImageIcon(getClass().getResource("/Images/status_busy.png")));
                break;
        }
        lbl_chatfriend.setText(friend);
    }
     public void setFriend(String str){
        lbl_chatfriend.setText(str);
    }
    
    public String getFriend(){
       return lbl_chatfriend.getText();
    }
    
    public void setUsername(String str){
        this.setTitle(str);
        username=str;       
    }
    public void setCount(int i){
        this.count=i;     
    }
    public int getCount(){
        return this.count;     
    }
     public void setWatch(int i){
        this.watch=i;     
    }
    public int getWatch(){
        return this.watch;     
    }
    
    // Hiển thị tin nhắn lên khung chat
    public void myMessage(String str){
        StyledDocument doc = tp_log.getStyledDocument();
        
        SimpleAttributeSet UserName = new SimpleAttributeSet();
        StyleConstants.setForeground(UserName, Color.darkGray);
        StyleConstants.setBold(UserName, true);
        
        SimpleAttributeSet normal = new SimpleAttributeSet();
        docStyle(normal, getStyle());
        try {
            doc.insertString(doc.getLength(),username+": ", UserName );
            doc.insertString(doc.getLength(), str+"\n", normal );
            new Sound().play("message");
            tp_log.select(doc.getLength(), doc.getLength());
        } catch (BadLocationException ex) {
        }
    }
    
    // Hiển thị tin nhắn nhận từ bạn
    public void friendMessage(String friendname, String style, String str){
        StyledDocument doc = tp_log.getStyledDocument();
        
        SimpleAttributeSet UserName = new SimpleAttributeSet();
        StyleConstants.setForeground(UserName, Color.BLUE);
        StyleConstants.setBold(UserName, true);
        
        SimpleAttributeSet normal = new SimpleAttributeSet();
        docStyle(normal, style);
        try {
            doc.insertString(doc.getLength(),friendname+": ", UserName );
            doc.insertString(doc.getLength(), str+"\n", normal );
            new Sound().play("message");
            tp_log.select(doc.getLength(), doc.getLength());
        } catch (BadLocationException ex) {
        }
    }
    
    // Lấy giá trị định dạng font
    public String getStyle(){
        String s="";
        if(btn_B.isSelected()){s+=1;} else s+=0;
        if(btn_I.isSelected()){s+=1;} else s+=0;
        if(btn_U.isSelected()){s+=1;} else s+=0;
        s+=String.format("%02d",cbo_font.getSelectedIndex());
        s+=String.format("%02d",cbo_size.getSelectedIndex());
        return s;
    }
    
    //Gán giá trị font cho Styleddocument
    public void docStyle(SimpleAttributeSet d, String s){
        if(s.substring(0,1).equals("0")) {
            StyleConstants.setBold(d, false);
        }
        else StyleConstants.setBold(d, true);

        if(s.substring(1,2).equals("0")) {
            StyleConstants.setItalic(d, false);
        }
        else StyleConstants.setItalic(d, true);

        if(s.substring(2,3).equals("0")) {
            StyleConstants.setUnderline(d,false);
        }
        else StyleConstants.setUnderline(d, true);

        int f=Integer.parseInt(s.substring(3,5));
        String font = (String)cbo_font.getItemAt(f);
        StyleConstants.setFontFamily(d,font);

        int idsize=Integer.parseInt(s.substring(5,7));
        int size = Integer.parseInt((String)cbo_size.getItemAt(idsize));
        StyleConstants.setFontSize(d, size);
    }
        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton btn_B;
    private javax.swing.JToggleButton btn_I;
    private javax.swing.JButton btn_Send;
    private javax.swing.JToggleButton btn_U;
    private javax.swing.JLabel buzz;
    private javax.swing.JComboBox cbo_font;
    private javax.swing.JComboBox cbo_size;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JLabel lb_smile;
    private javax.swing.JLabel lbl_chatfriend;
    private javax.swing.JLabel lbl_lock;
    private javax.swing.JMenu mn_Help;
    private javax.swing.JMenu mn_chucnang;
    private javax.swing.JMenu mn_hoithoai;
    private javax.swing.JMenuItem mni_AddFriend;
    private javax.swing.JMenuItem mni_Close;
    private javax.swing.JMenuItem mni_Info;
    private javax.swing.JMenuItem mni_Lock;
    private javax.swing.JMenuItem mni_New;
    private javax.swing.JMenuItem mni_Unlock;
    private javax.swing.JMenu mnu_Friend;
    private javax.swing.JPanel pn_smiley;
    private javax.swing.JLabel smile1;
    private javax.swing.JLabel smile10;
    private javax.swing.JLabel smile11;
    private javax.swing.JLabel smile12;
    private javax.swing.JLabel smile13;
    private javax.swing.JLabel smile14;
    private javax.swing.JLabel smile15;
    private javax.swing.JLabel smile16;
    private javax.swing.JLabel smile17;
    private javax.swing.JLabel smile18;
    private javax.swing.JLabel smile19;
    private javax.swing.JLabel smile2;
    private javax.swing.JLabel smile20;
    private javax.swing.JLabel smile21;
    private javax.swing.JLabel smile22;
    private javax.swing.JLabel smile23;
    private javax.swing.JLabel smile24;
    private javax.swing.JLabel smile3;
    private javax.swing.JLabel smile4;
    private javax.swing.JLabel smile5;
    private javax.swing.JLabel smile6;
    private javax.swing.JLabel smile7;
    private javax.swing.JLabel smile8;
    private javax.swing.JLabel smile9;
    private javax.swing.JTextField tf_message;
    private javax.swing.JTextPane tp_log;
    // End of variables declaration//GEN-END:variables

}
